package kr.hkit.powerjava.chapter18;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.BoxLayout;

import java.awt.GridLayout;

import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Panel_Dialog extends JPanel implements ActionListener {
	private JButton btnMessage;
	private JButton btnMessage2;
	private JButton btnMessage3;
	private JButton btnMessage4;
	private JButton btnMessage5;
	private JButton btnMessage6;

	/**
	 * Create the panel.
	 */
	public Panel_Dialog() {

		initialize();
	}
	private void initialize() {
		setLayout(new GridLayout(0, 1, 0, 0));
		
		btnMessage = new JButton("Show Message Dialog(Warnning)");
		btnMessage.addActionListener(this);
		add(btnMessage);
		
		btnMessage2 = new JButton("Show Message Dialog(Error)");
		btnMessage2.addActionListener(this);
		add(btnMessage2);
		
		btnMessage3 = new JButton("Show Option Dialog(Yes No Cancel)");
		btnMessage3.addActionListener(this);
		add(btnMessage3);
		
		btnMessage4 = new JButton("Show Option Dialog(Yes No))");
		btnMessage4.addActionListener(this);
		add(btnMessage4);
		
		btnMessage5 = new JButton("Show Input Dialog(ComboBox)");
		btnMessage5.addActionListener(this);
		add(btnMessage5);
		
		btnMessage6 = new JButton("Show Input Dialog(TextField)");
		btnMessage6.addActionListener(this);
		add(btnMessage6);
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == btnMessage6) {
			actionPerformedBtnMessage6(e);
		}
		if (e.getSource() == btnMessage5) {
			actionPerformedBtnMessage5(e);
		}
		if (e.getSource() == btnMessage4) {
			actionPerformedBtnMessage4(e);
		}
		if (e.getSource() == btnMessage3) {
			actionPerformedBtnMessage3(e);
		}
		if (e.getSource() == btnMessage2) {
			actionPerformedBtnNewButton_1(e);
		}
		if (e.getSource() == btnMessage) {
			actionPerformedBtnMessage(e);
		}
	}
	protected void actionPerformedBtnMessage(ActionEvent e) {
		JOptionPane.showMessageDialog(this, "범위 초과 ", "갱고", JOptionPane.WARNING_MESSAGE); //부모 메세지 타이틀 메세지타입
		
	}
	protected void actionPerformedBtnNewButton_1(ActionEvent e) {
		JOptionPane.showMessageDialog(this, "입력 오류 ", "오류", JOptionPane.ERROR_MESSAGE); //부모 메세지 타이틀 메세지타입
	}
	protected void actionPerformedBtnMessage3(ActionEvent e) {
		String[] options = {"Well-done","Medium","Rare"};
		int res = JOptionPane.showOptionDialog(this, "스테이크를 어떻게 요리할까요?", "스테이크 주문", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
		JOptionPane.showMessageDialog(null, options[res]+"선택하셨습니다.");
		
	}
	protected void actionPerformedBtnMessage4(ActionEvent e) {
		String[] options ={"예","아니오"};
		int res = JOptionPane.showOptionDialog(this, "수업 마칠까요?", "종료질의", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
		JOptionPane.showMessageDialog(null, options[res]+"쉬었다 할게염.");
	}
	protected void actionPerformedBtnMessage5(ActionEvent e) {
		String[] selectionValues={"우유","콜라","커피"};
		String res = (String) JOptionPane.showInputDialog(this, "후식을 선택해라", "후식", JOptionPane.INFORMATION_MESSAGE, null, selectionValues, selectionValues[0]);
		JOptionPane.showMessageDialog(this, res);
	}
	protected void actionPerformedBtnMessage6(ActionEvent e) {
		String res = (String) JOptionPane.showInputDialog(this, "후식을 선택해라", "후식", JOptionPane.INFORMATION_MESSAGE, null, null, "아이스크림");
		JOptionPane.showMessageDialog(this, res);
	}
}
